package net.tv90.auth.utils;

import net.tv90.auth.model.LoginStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class UserUtils {

    private final static int EXPIRE_TIME_DAY = 2;
    private final static String PREFIX = "loginUser::";

    @Autowired
    RedisUtils redisUtils;

    //@CachePut(value = "loginUser", key = "#username")
    public void login(String username, LoginStatus loginStatus) {
        redisUtils.setObject(PREFIX + username, loginStatus, EXPIRE_TIME_DAY, TimeUnit.DAYS);
    }

    //@CacheEvict(value = "loginUser", key = "#username")
    public void logout(String username) {
        redisUtils.deleteObject(PREFIX + username);
    }

    public LoginStatus getUserLoginStatus(String username) {
        return redisUtils.getObject(PREFIX + username);
    }

}
